package acm;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

//无限Set，若a在set,b也在set,那么a+b也添加到set
public class InfiniteSet {

	public static void main(String[] args) {
		TreeSet<Integer> treeSet = new TreeSet<Integer>();
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int query_time = scanner.nextInt();
		int count = 0;
		int[] query = new int[query_time];
		for (int i = 0; i < query_time; i++) {
			query[i] = scanner.nextInt();
		}
		long first_time = System.currentTimeMillis();
		System.out.println(first_time);
		// 确定查询的最大项
		int max_query = query[query_time - 1];
		for (int i = 0; i < query_time - 1; i++) {
			max_query = query[i] < query[i + 1] ? query[i] : query[i + 1];
		}
		scanner.close();
		treeSet.add(a);
		treeSet.add(b);
		while (true) {
			Integer[] temp = new Integer[treeSet.size()];
			treeSet.toArray(temp);
			for (int i = 0; i < temp.length - 1; i++) {
				for (int j = i + 1; j < temp.length; j++) {
					// 若a，b在集合里面，那么将a+b添加进去
					treeSet.add(2 * temp[i]);
					treeSet.add(2 * temp[j]);
					treeSet.add(temp[i] + temp[j]);
				}
			}
			if (treeSet.size() >= 1.5 * max_query) {
				break;
			}
		}
		ArrayList<Integer> list = new ArrayList<Integer>(treeSet); // 将set转换成list
		for (; count < query_time;) {
			if (treeSet.size() >= query[count]) {
				System.out.println(list.get(query[count] - 1));
				count++;
			}
		}
		// System.out.println(System.currentTimeMillis()-first_time+"ms");
	}
}
